package com.wangys.controller;


import com.wangys.entities.Sdb;
import com.wangys.mapper.SdbMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@ResponseBody
@CrossOrigin
@RequestMapping("/sdb")
public class SdbController {
    @Autowired(required = false)
    private SdbMapper sdbMapper;

    @RequestMapping("/select")
    public List<Sdb> select(){
        return  sdbMapper.select();

    }
    @RequestMapping("/add")
    public void add(Sdb sdb){
        sdbMapper.add(sdb);
    }
    @RequestMapping("/delete")
    public void delete(int id){
        sdbMapper.delete(id);
    }
    @RequestMapping("/byId")
    public Sdb byId(int id){
        return sdbMapper.byId(id);
    }
    @RequestMapping("/update")
    public void update(Sdb sdb){
        sdbMapper.update(sdb);
    }
    @RequestMapping("/deleteAll")
    public void deleteAll(String ids){
        String[] split = ids.split(",");
        List<Integer> arrayList=new ArrayList<Integer>();
        for ( String iid:split) {
            arrayList.add(Integer.parseInt(iid));
        }
        sdbMapper.deleteAll(arrayList);
    }
    @RequestMapping("/getCount")
    public List<Sdb> getCount(){
        return sdbMapper.getCount();
    }
    @RequestMapping("/like")
    public List<Sdb> like(Sdb sdb){
        return sdbMapper.like(sdb);
    }
}
